/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#pragma once
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>

typedef enum
{
    ARG_TYPE_NONE = 0,
    ARG_TYPE_C,   // char
    ARG_TYPE_SH,  // short
    ARG_TYPE_I,   // int
    ARG_TYPE_LL,   // long long
    ARG_TYPE_F,   // float
    ARG_TYPE_D,   // double
    ARG_TYPE_STR, // string
} ARG_TYPE_ENUM;

typedef struct
{
    const char *explain;
    const char *namel;
    const char names;
    const char has_arg; // no_argument, required_argument, optional_argument
    uint8_t valtype;
    uint8_t valsize;
    // c11 surpport anonymous struct or union. before c11, need modify code!
    union valptrType
    {
        char *val_c;
        short *val_s;
        int *val_i;
        int64_t *val_ll;
        float *val_f;
        double *val_d;
        char *val_str;
        void *val_com;
    } valptr;
} argParseStc;

#define FACTORY_ARG_PS_COM(nl, ns, epl, h_a, v_t, v_s, v_p) {.namel = nl, .names = ns, .explain = epl, .has_arg = h_a, .valtype = v_t, .valsize = v_s, .valptr.val_com = v_p}

typedef struct
{
    int argsize;
    argParseStc *argbuf;
} argBuffStc;

int parseArgCom(int argc, char **argv, argBuffStc *getArgBuf);
int printOptArgInfo(argBuffStc *getArgBuf);
